package arena;

import gameObjects.Bike.TANK_COLOR;
import java.awt.Toolkit;
import java.io.IOException;
import javax.swing.JOptionPane;

import radar.Radar;
import menu.PanelMain;

import com.jme.app.BaseGame;
import com.jme.input.MouseInput;
import com.jme.renderer.ColorRGBA;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;

public class Arena extends BaseGame{
	public static final ColorRGBA colorRed = new ColorRGBA(1.0f, 0.0f, 0.0f, 0.5f);
	public static final ColorRGBA colorAmb = new ColorRGBA(0.5f, 0.5f, 0.5f, 0.1f);
	public StandardGame game;
	public ArenaGS gs;
	public PanelMain pm;
	private Toolkit kit = Toolkit.getDefaultToolkit();
	private String levelName;
	private TANK_COLOR color;
	private int players;
	private ArenaRPS rps;
	
	public Arena(String levelName,int color,int players,int screen, boolean musicOn, boolean effectsOn) throws IOException, InterruptedException
	{	
		int[] width  = {640,640,720,800,1024,kit.getScreenSize().width};
		int[] height = {300,480,576,600,1078,kit.getScreenSize().height}; 
		String[] colors = {"black","red","green","gray","blue","yellow"};
		
		game = new StandardGame("TRACE-ON");
		game.getSettings().setStencilBits(4);
		game.getSettings().setDepth(24);
		game.getSettings().setAlphaBits(0);
		game.getSettings().setSamples(0);
		game.getSettings().setWidth(width[screen]);
		game.getSettings().setHeight(height[screen]);
		game.getSettings().setFullscreen(false);
		game.getSettings().setMusic(musicOn);
		game.getSettings().setSFX(true);
		game.start();
		
		this.pm=PanelMain.getInstance();
		this.levelName=levelName;
		this.color=TANK_COLOR.valueOf(colors[color]);
		this.players=players;
		reinit();
	}
	
	public static void main(String[] args) {
		JOptionPane.showMessageDialog(null, args.toString());
	}

	@Override
	protected void cleanup() {
		// TODO Auto-generated method stub
		game.finish();
		this.quit();
		System.exit(0);
	}

	@Override
	protected void initGame() {
		// TODO Auto-generated method stub
	}

	@Override
	protected void initSystem() {
		System.out.println("LEVEL NAME:" + levelName);
		MouseInput.get().setCursorVisible(false);
		gs = ArenaGS.getInstance();
		gs.setGame("GS",color.ordinal(),players,levelName,this);
		
		GameStateManager.getInstance().detachAllChildren();
		GameStateManager.getInstance().attachChild(gs);
		gs.setActive(true);
		
		rps = ArenaRPS.getInstance();
		GameStateManager.getInstance().attachChild(rps);
		rps.setActive(true);
		gs.setRps(rps);
	}

	@Override
	protected void reinit() {
		initSystem();
	}

	@Override
	protected void render(float paramFloat) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void update(float paramFloat) {
		// TODO Auto-generated method stub
		
	}
}
